package net.bwie.jtp.dws.log.Function;

import net.bwie.jtp.dws.log.bean.PageViewBean;
import org.apache.flink.api.common.functions.ReduceFunction;


//对每分钟窗口中数据进行增量计算,创建ReduceFunction函数实例,ReduceFunction函数要求聚合结果类型，必须与窗口中数据类型一致。
public class PageViewReportReduceFunction implements ReduceFunction<PageViewBean> {
    @Override
    public PageViewBean reduce(PageViewBean value1, PageViewBean value2) throws Exception {
        //value1：表示增加计算中间结果；value2：表示窗口中每条数据

        // 1增量计算：各个指标值相加
        value1.setPvCount(value1.getPvCount() + value2.getPvCount());
        value1.setPvDuringTime(value1.getPvDuringTime() + value2.getPvDuringTime());
        value1.setUvCount(value1.getUvCount() + value2.getUvCount());
        value1.setSessionCount(value1.getSessionCount() + value2.getSessionCount());
        // 2返回结果
        return value1;

    }
}
